import { getSetting } from "../api/setting";
import { titleController } from "../utils"
export default {
    namespaced: true,
    state: {
        data: {},
        loading: false,
    },

    mutations: {
        install(state, payload) {
            state.data = payload;
        },
        setLoading(state, payload) {
            state.loading = payload;
        }
    },
    actions: {
        async fetchsetting(ctx) {
            ctx.commit('setLoading', true);
            const resp = await getSetting();
            ctx.commit('install', resp);
            ctx.commit('setLoading', false);
            if (resp.favicon) {
                let link = document.querySelector('link[rel = "shortcout icon"]')
                    // {/* < link rel = "shortcut icon" type = "image/x-icon" href = "favicon.ico"/ */}
                if (link) {
                    return
                }
                link = document.createElement('link')
                link.rel = "shortcut icon";
                link.type = "image/x-icon"
                link.href = resp.favicon;
                document.querySelector('head').appendChild(link);
            };
            if (resp.siteTitle) {
                titleController.setSiteTitle(resp.siteTitle);
            }

        }
    }
}